/* 
 * Modbus app for RTU.
 * Copyright (c) 2012  apleilx
 * All rights reserved.
 * no limite
 */

/* ----------------------- Platform includes --------------------------------*/
#define _MAPP_MODULE_
#include "mbapp.h"
#include "pincfg.h"
#include "mbport_00.h"
#include "mbport_01.h"
#include "mbport_02.h"
#include "mbport_03.h"
#include "systask.h"
#include "mbdef.h"
#include "vgus_dev.h"
#include "systimer.h"
void input_updata(void);
mb_baud_tab_create;    
uint16_t DataRecevie[64];
uint8_t mbTestErrCnt = 0;
uint8_t mbTestOkCnt = 0;
uint8_t b_mb_inited = 0;

volatile uint32_t dgs_err;
volatile uint32_t dgs_ok;

void dgus_callback(uint8_t CmdSite, uint8_t ErrSt)
{
    if(ErrSt)
    {
        dgs_err++;
    }
    else
    {
       dgs_ok++; 
    }    
}

/*****************************************************************************//*!
* @brief   	Slave device handle.
*               
* @param   none
*
* @return  none
*
* @ Pass/ Fail criteria: none
*****************************************************************************/   
void modbus_task ()
{
    input_data();
    mb_poll(&mb.obj00);
    mb_poll(&mb.obj01);
}


/*
* modbus init
*/
void modbus_init()
{
        mb00_Init( MB_RTU_MASTER, 115200,   MB_PAR_NONE);
        mb.obj00.SlaveId=1; 
        mb.obj00.RtuRcvendDelaySet = 20;
        mb.obj00.os_event_send =0;
        mb.obj00.os_rtu_end_event = 0x01;
        mb.obj00.os_timeout_event = 0x02;
        b_mb_inited = 1;
   
        mb01_Init( MB_RTU_SLAVE, 1152000,   MB_PAR_NONE);
        mb.obj01.SlaveId=1; 
        mb.obj01.RtuRcvendDelaySet = 20;
        mb.obj01.os_event_send =0;
        mb.obj01.os_rtu_end_event = 0x01;
        mb.obj01.os_timeout_event = 0x02;
        b_mb_inited = 1;  
}


/*
* test call back
*/
void mbTestCallBack(uint8_t CmdSite, uint8_t ErrSt){
    if(ErrSt)
        mbTestErrCnt++; 
    else
        mbTestOkCnt++;
}


/*
* input data handle
*/
void input_data (void)
{
    
}
